package com.wuseguang.springcloud.controller;

import com.wuseguang.springcloud.Filter.RequestParameterWrapper;
import com.wuseguang.springcloud.service.ParentActivitiyService;
import com.wuseguang.springcloud.util.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @描述 家长会议签到
 * @创建人 zm
 * @创建时间 2020/5/13
 */
@RestController
@RequestMapping("/jurisdiction")
public class ParentActivitiyController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ParentActivitiyService service;


    /**
     * @描述 查询家长签到活动(教师端)
     * @创建人 zm
     * @创建时间 2020/5/11
     */
    @RequestMapping("/queryParentActivitiyList")
    public Result queryParentActivitiyList(RequestParameterWrapper request,
                                           @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                           @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows) {
        String schoolId = request.getParam("schoolId");//学校id
        String admin = request.getParam("admin");// 0 管理员 1非管理员
        String teacherId = request.getParam("teacherId");//教师id
        logger.info("queryParentActivitiyList-->schoolId={},admin={},teacherId={}", schoolId, admin, teacherId);
        return service.queryParentActivitiyList(Integer.parseInt(schoolId), indexNo, rows, teacherId, admin);
    }

    /**
     * @描述 根据id查活动信息
     * @创建人 zm
     * @创建时间 2020/6/8
     */
    @RequestMapping("/queryParentActivitiyById")
    public Result queryParentActivitiyById(@RequestParam(value = "id") Integer id) {
        return service.queryParentActivitiyById(id);
    }

    /**
     * @描述 添加家长活动(教师端)
     * @创建人 zm
     * @创建时间 2020/5/11
     */
    @RequestMapping("/addParentActivitiy")
    public Result addParentActivitiy(RequestParameterWrapper request,
                                     @RequestParam(value = "classId") Integer classId,//班级id
                                     @RequestParam(value = "stime") String stime,//开始时间
                                     @RequestParam(value = "etime") String etime,//结束时间
                                     @RequestParam(value = "name") String name,//活动主题
                                     @RequestParam(value = "state") String state) {//是否通知家长
        String schoolId = request.getParam("schoolId");
        String teacherId = request.getParam("teacherId");//教师id
        logger.info("addParentActivitiy-->schoolId={},classId={}", schoolId, classId);
        return service.addParentActivitiy(Integer.parseInt(schoolId), classId, stime, etime, name, state,teacherId);
    }

    /**
     * @描述 修改活动信息(教师端)
     * @创建人 zm
     * @创建时间 2020/5/11
     */
    @RequestMapping("/updateParentActivitiy")
    public Result updateParentActivitiy(@RequestParam(value = "id") Integer id,//活动id
                                        @RequestParam(value = "classId") Integer classId,//班级id
                                        @RequestParam(value = "stime") String stime,//开始时间
                                        @RequestParam(value = "etime") String etime,//结束时间
                                        @RequestParam(value = "name") String name) {//活动主题
        logger.info("updateParentActivitiy-->id={},classId={}", id, classId);
        return service.updateParentActivitiy(id, classId, stime, etime, name);
    }


    /**
     * @描述 修改活动开始/结束状态 0为 未开始 1为开始 展示在班牌(教师端)
     * @创建人 zm
     * @创建时间 2020/5/11
     */
    @RequestMapping("/updateParentActivitiyStart")
    public Result updateParentActivitiyStart(@RequestParam(value = "id") Integer id,//活动id
                                             @RequestParam(value = "start") Integer start,//0为 未开始 1为开始
                                             @RequestParam(value = "classId") Integer classId) {//班级id
        logger.info("updateParentActivitiy-->id={},classId={},state={}", id, classId, start);
        return service.updateParentActivitiyStart(id, start, classId);
    }

    /**
     * @描述 根据id删除活动信息(教师端)
     * @创建人 zm
     * @创建时间 2020/5/11
     */
    @RequestMapping("/delParentActivitiy")
    public Result delParentActivitiy(@RequestParam(value = "id") Integer id) {//活动id
        return service.delParentActivitiy(id);
    }

    /**
     * @描述 查看已到人数/或未到人数(教师端)
     * @创建人 zm
     * @创建时间 2020/5/11
     */
    @RequestMapping("/queryActivitiyArrived")
    public Result queryActivitiyArrived(@RequestParam(value = "id") Integer id,//活动id
                                        @RequestParam(value = "type") Integer type,
                                        @RequestParam(value = "indexNo", required = false, defaultValue = "1") Integer indexNo,
                                        @RequestParam(value = "rows", required = false, defaultValue = "20") Integer rows) {//type 0 已到 1未到
        return service.queryActivitiyArrived(id, type, indexNo, rows);
    }


    /**
     * @描述 根据学生id查询家长活动(家长端)
     * @创建人 zm
     * @创建时间 2020/5/11
     */
    @RequestMapping("/queryActivitiyByStudentId")
    public Result queryActivitiyByStudentId(@RequestParam(value = "studentId") Integer studentId) {//学生id
        return service.queryActivitiyByStudentId(studentId);
    }


    /**
     * @描述 扫一扫，二维码签到
     * @创建人 zm
     * @创建时间 2020/5/11
     */
    @RequestMapping("/addSigned")
    public Result addSigned(@RequestParam(value = "id") Integer id,//活动id
                            @RequestParam(value = "time") String time,//二维码生成时间
                            @RequestParam(value = "studentId") Integer studentId) {//学生id
        return service.addSigned(id, time, studentId);
    }
}
